import 'package:fluent_ui/fluent_ui.dart' hide Page;
import 'package:flutter/foundation.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart' as flutter_acrylic;
import 'package:url_strategy/url_strategy.dart';
import 'package:window_manager/window_manager.dart';

import 'app.dart';
import 'db/database.dart';
import 'widgets/deferred_widget.dart';
/// Checks if the current environment is a desktop environment.
bool get isDesktop {
  if (kIsWeb) return false;
  return [
    TargetPlatform.windows,
    TargetPlatform.linux,
    TargetPlatform.macOS,
  ].contains(defaultTargetPlatform);
}

late AppDatabase database;

void main() async {

  WidgetsFlutterBinding.ensureInitialized();

  // if it's not on the web, windows or android, load the accent color
  if (!kIsWeb &&
      [
        TargetPlatform.windows,
        TargetPlatform.android,
      ].contains(defaultTargetPlatform)) {
    // SystemTheme.accentColor.load();
  }

  setPathUrlStrategy();

  if (isDesktop) {
    await flutter_acrylic.Window.initialize();
    await WindowManager.instance.ensureInitialized();
    windowManager.waitUntilReadyToShow().then((_) async {
      await windowManager.setTitleBarStyle(
        TitleBarStyle.hidden,
        windowButtonVisibility: false,
      );
      await windowManager.setSize(const Size(1200, 800));
      await windowManager.setMinimumSize(const Size(800, 800));
      await windowManager.center();
      await windowManager.show();
      await windowManager.setPreventClose(true);
      await windowManager.setSkipTaskbar(false);
    });
  }


  // ignore: unused_local_variable
   database = await $FloorAppDatabase
      .databaseBuilder('customer_data.db')
      .build();

  runApp(const MyApp());

  // DeferredWidget.preload(forms.loadLibrary);
  // DeferredWidget.preload(inputs.loadLibrary);
  // DeferredWidget.preload(navigation.loadLibrary);
  // DeferredWidget.preload(surfaces.loadLibrary);
  // DeferredWidget.preload(theming.loadLibrary);
  // DeferredWidget.preload(edit.loadLibrary);
  // DeferredWidget.preload(product.loadLibrary);
}



